home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / network-manager / ifblacklist_migrate.sh
Encoding:
Linux/UNIX/POSIX Shell Script  |  2009-04-14  |  1.7 KB  |  68 lines

  1. #!/bin/sh
  2.  
  3. # (C) 2007 Canonical Ltd.
  4. # Author: Alexander Sack <asac@jwsdot.com>
  5. # License: GNU General Public License, version 2 or any later version
  6.  
  7. if test x$NIF_FILE = x; then
  8.    NIF_FILE=/etc/network/interfaces
  9. fi
  10.  
  11. auto_ifs=$(cat $NIF_FILE | \
  12.     egrep "^auto|^allow-" | \
  13.     sed -e 's/auto//' | \
  14.     sed -e 's/allow-[^ ].* //')
  15.  
  16. ifaces_to_disable=""
  17.  
  18. echo Auto interfaces found: $auto_ifs
  19.  
  20. # iterate over all auto interfaces
  21. for i in $auto_ifs; do
  22.   IFS_old=$IFS; IFS=""
  23.  
  24.   NIF_FILE_content=$(cat $NIF_FILE | \
  25.       sed -e 's/^[ \t]*auto.*$//' | \
  26.       sed -e 's/^[ \t]*allow-.*$//' | \
  27.       sed -e 's/^[ \t]*#.*$//' | grep -v ^$)
  28.  
  29.   # '--' is inserted by grep -A1 if there are multiple iface blocks
  30.   lines=$(echo $NIF_FILE_content | grep -A1 "^iface.*$i.*dhcp" | grep -v '\--')
  31.   IFS="
  32. "
  33.  
  34.   # if there is no iface line for that interface, we would still get a line
  35.   # count of 1 ... so use word_count 0 below to exclude ifaces that have no
  36.   # configuration at all.
  37.   word_count=$(echo $lines | wc -w)
  38.   line_count=0
  39.   for line in $lines; do
  40.       nulled_line=$(echo $line | sed -e 's/[# ]//' | grep -v ^iface)
  41.       if test x$nulled_line != x; then
  42.       line_count=$(expr $line_count + 1)
  43.       fi
  44.   done  
  45.  
  46.   if test $line_count -eq 0 -a $word_count -gt 0; then
  47.      ifaces_to_disable="$ifaces_to_disable $i"
  48.      echo iface to disable = $i
  49.   fi
  50.   IFS=$IFS_old
  51. done
  52.  
  53. backup_suffix=0
  54. while test -e ${NIF_FILE}.bak-${backup_suffix}; do
  55.    backup_suffix=$(expr $backup_suffix + 1)
  56. done
  57.  
  58. for i in $ifaces_to_disable; do
  59.   echo -n "Disabling interface: $i ... "
  60.   sed -i.bak-${backup_suffix} -e "
  61. s/^\([ \t]*iface.*$i.*\)$/#\1/" $NIF_FILE
  62.   # for now don't kill any auto lines
  63.   # s/^\([ \t]*auto.*$i.*\)$/#\1/ 
  64.   # s/^\([ \t]*allow-.*$i.*\)$/#\1/
  65.  
  66.   echo done.
  67. done
  68.